<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>机场管理</title>
    <% include("/common/common_css_js.html"){} %>
</head>
<body>
    <div style="padding-bottom: 5px;">
        <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
            <span class="separator"></span>
            <span>机场名称：</span>
            <input name="name" class="mini-textbox" />
            <span>机场别名：</span>
            <input name="shortName" class="mini-textbox" />
            <span>所在城市：</span>
            <input id="queryFormCityId" name="cityId" class="mini-treeselect"
                   url="" multiSelect="false" valueField="id" textField="name"
                   parentField="pid" allowInput="true" valueFromSelect="true"  virtualScroll="true"
                   style="width: 250px;" expandOnLoad="0" required="false" />
            <span class="separator"></span>
            <% if(so.hasPermission("xtAirport:query")){%>
                <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
            <% } %>

            <span class="separator"></span>
            <% if(so.hasPermission("xtAirport:queryCndClear")){%>
                <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
            <% } %>

        </div>
    </div>

    <div class = "mini-fit">
        <div id="datagrid1" class="mini-datagrid"
             style="width: 100%; height: 100%;"
             url="${base}/pages/basic_data_manage/xt_airport/query" idField="id"
             showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
             allowResize="true"
             allowCellWrap="true">
            <div property="columns">
                <div field="name" width="140" headerAlign="center" align="center" allowSort="true">机场名称</div>
                <div field="shortName" width="140" headerAlign="center" align="center" allowSort="true">机场别名</div>
                <div field="threeCode" width="140" headerAlign="center" align="center" allowSort="true">三字码</div>
                <div field="fourCode" width="140" headerAlign="center" align="center" allowSort="true">四字码</div>
                <div field="cityIds" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city",splitStr:" "}' renderer="commonMulRender">所在城市</div>
<!--                <div width="140" headerAlign="center" align="center" renderer="operRenderer">操作</div>-->
            </div>
        </div>
    </div>

    <!--编辑窗口-->
    <div id="updatePanel" class="mini-window" title="机场管理" style="width:700px;height:400px;"
         showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
         showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
        <div property="footer" style="padding:10px;text-align: right">
            <a  id="insertOrUpdateSaveBtn" name="insertOrUpdateSaveBtn" class="mini-button" iconCls="icon-save" onclick="saveInsertOrUpdate()">保存</a>
        </div>
        <div id="airportForm">
            <table style="width: 100%">
                <tr>
                    <td><label>ID:</label></td>
                    <td colspan="3"><input id="id" name="id"  class="mini-textbox"  required="true" />
                    </td>
                </tr>
                <tr>
                    <td><label>机场名称:</label></td>
                    <td><input id="name"  name="name"  class="mini-textbox" required="true" requiredErrorText="名称不能为空" onblur="nameOnblur" emptyText="请输入机场名称"/></td>
                    <td><label>机场拼音:</label></td>
                    <td><input id="fullPinyin" name="fullPinyin"  class="mini-textbox" required="true" requiredErrorText="拼音不能为空" emptyText="请输入机场拼音"/></td>
                </tr>
                <tr>
                    <td><label>英文名称:</label></td>
                    <td><input name="nameEn"  class="mini-textbox" required="false" requiredErrorText="英文名称不能为空" vtype="english"  emptyText="请输入英文名称" /></td>
                </tr>
                <tr>
                    <td><label>机场名称简称:</label></td>
                    <td><input id="shortName" name="shortName"  class="mini-textbox" required="false" requiredErrorText="机场名称简称不能为空" emptyText="请输入机场名称简称" onblur="getPinyin('shortName','shortNamePinyin')"/></td>
                    <td><label>机场简称全拼音:</label></td>
                    <td><input id="shortNamePinyin" name="shortNamePinyin"  class="mini-textbox" required="false" emptyText="请输入机场简称全拼音" requiredErrorText="机场简称全拼音能为空"/></td>
                </tr>
                <tr>
                    <td><label>三字码:</label></td>
                    <td><input name="threeCode" class="mini-textbox" required="false" emptyText="请输入三字码"  requiredErrorText="三字码不能为空"/></td>
                    <td><label>四字码:</label></td>
                    <td><input name="fourCode"  class="mini-textbox" required="false" emptyText="请输入四字码"   requiredErrorText="四字码不能为空"/></td>
                </tr>
                <tr>
                    <td><label>所在城市:</label></td>
                    <td colspan="3"><input id="cityIds" name="cityIds" class="mini-treeselect"
                               url="" multiSelect="false" valueField="id" textField="name"
                               parentField="pid" allowInput="true" valueFromSelect="true" showFolderCheckBox="true"
                               style="width: 250px;" expandOnLoad="0" required="true" nullItemText="请选择..." requiredErrorText="所在城市不能为空"/>

                    </td>
                </tr>
                <tr>
                    <td><label>备注:</label></td>
                    <td colspan="3"><input name="comment" class="mini-textarea" required="false" requiredErrorText="备用字段3不能为空" style="width:550px;height: 60px;"/></td>
                </tr>
            </table>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        let grid = mini.get("datagrid1");
        let oper;
        let airportForm = new mini.Form("#airportForm");

        $(function () {
            // 加载列表数据
            grid.load();

            //新增、修改弹出框默认操作
            oper = OPER_ADD();

            // 加载弹出窗口的有效性下拉列表  city
            let jsonData = commonRenderDropList("city");

            mini.get("queryFormCityId").loadList(jsonData, "id", "pid");
            mini.get("cityIds").loadList(public_deepClone(jsonData), "id", "pid");
        });

        function search() {
            let form = new mini.Form("#queryForm");
            let data = form.getData(true);
            grid.load(data);
        }

        function clearSearch() {
            let form = new mini.Form("#queryForm");
            form.clear();
        }

        function add(){
            airportForm.clear();
            oper = OPER_ADD();
            //设置id允许输入
            mini.get("id").setEnabled(true);
            // 弹出添加窗口
            public_showModelAtPos("updatePanel", "center", "middle");
        }

        function update(){
            airportForm.clear();
            // 获取当前选中的行
            let row = grid.getSelected();
            if(!row){
                mini.alert("请选择要编辑的行!","字典编辑",null);
                return;
            }
            airportForm.setData(row);
            oper = OPER_UPDATE();
            //设置id不允许输入
            mini.get("id").setEnabled(false);
            // 弹出添加窗口
            public_showModelAtPos("updatePanel", "center", "middle");
        }

        //新增保存或修改保存
        function saveInsertOrUpdate(){
            // 添加并保存
            airportForm.validate();
            if (airportForm.isValid() == false){
                public_showErrorTips("请将信息填写完整再进行下一步！");
                return;
            }
            let data = airportForm.getData(true);

            let methodName = oper == OPER_ADD() ? "insert" : "update";
            let ret = public_getServerData("${base}/pages/basic_data_manage/xt_airport/" + methodName,data);
            public_showTip(ret);
            if(ret.ok) {
                refreashCache();
                // 重新刷新数据
                grid.load();
                public_onCancel('updatePanel');
            }
        }

        //操作
        function operRenderer(e) {
            let record = e.record;
            let id = record.id;
            let s = "";
            s += '<a class="New_Button" href="javascript:update(\'' + id + '\')">编辑</a>';
            return s;
        }

        function deleteAirport(){
            let select = grid.getSelected();
            if(select == null){
                public_showErrorTips("未选中");
                return;
            }
            mini.confirm(
                "确定删除？",
                "确定？",
                function(action) {
                    if (action == "ok") {
                        let ret = public_getServerData("${base}/pages/basic_data_manage/xt_airport/delete?id=" + select.id);
                        public_showTip(ret);
                        if(ret.ok) {
                            refreashCache();
                            // 重新刷新数据
                            grid.removeRow(select, true);
                        }
                    }
                });
        }

        function nameOnblur(){
            getPinyin('name','fullPinyin');
            let name = mini.get("name").getValue();
            mini.get("shortName").setValue(name);
            getPinyin('shortName','shortNamePinyin')
        }


        function getPinyin(accordingElement,setElement) {
            let name = mini.get(accordingElement);
            let converValue = pinyin.getFullChars(name.value);
            mini.get(setElement).setValue(converValue);
        }

        //验证客户拼音的正确性
        mini.VTypes["english"] = function(v) {
            let re = new RegExp("[a-zA-Z 0-9]+$");
            if (re.test(v))
                return true;
            return false;
        }

        // 刷新缓存，把刷新的缓存放到父页面，应当调用父级页面方法刷新
        function refreashCache() {
            parent.window.loadCache();
        }


    </script>
</body>
</html>